﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Happy.StateManager.Test.Stub
{
    class Order
    {
        private readonly StateTable<Status, Operation> _stateTable;

        public Status Status { get; internal set; }

        public Order()
        {
            _stateTable = StateTable<Status, Operation>
                    .Config(() => this.Status, status => this.Status = status)
                    .In(Status.UnSaved).When(Operation.Save).Aways().TransferTo(Status.Saved)
                    .In(Status.Saved).When(Operation.Submit).Aways().TransferTo(Status.Submitted)
                    .Done();
        }

        public void Save()
        {
            _stateTable.Schedule(Operation.Save);
        }

        public void Submit()
        {
            _stateTable.Schedule(Operation.Submit);
        }

        public void Edit()
        {
            _stateTable.Schedule(Operation.Edit);
        }
    }
}
